import React, { Component } from 'react';
import { TableModelState, Loading, connect } from 'umi';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { Card, Table } from 'antd';


interface State {
    data: any;
    pageNo: number;
    pageSize: number;
    total: number;
}

interface Props {
    [key: string]: any;
}

const columns: any = [
    {
        title: '资产编码',
        dataIndex: 'FIXEDASSETNO',
        render: (text: string) => <a>{text}</a>,
    },
    {
        title: '资产名称',
        dataIndex: 'DESCRIPTION',
    },
    {
        title: '状态',
        dataIndex: 'FIXEDASSETSTATUSDESC',
    },
    {
        title: '启用时间',
        dataIndex: 'FASTATUSTIME',
    }, {
        title: '管理者',
        dataIndex: 'INTENDANTDESC',
    }, {
        title: '使用者',
        dataIndex: 'FAUSERDESC',
    }, {
        title: '使用部门',
        dataIndex: 'USERDEPTDESC',
    }, {
        title: '使用地点',
        dataIndex: 'USESITE',
    }, {
        title: '品牌',
        dataIndex: 'BRAND',
    }, {
        title: '型号',
        dataIndex: 'MODELREF',
    }, {
        title: '型号',
        dataIndex: 'MODELREF',
    }, {
        title: '出厂编号',
        dataIndex: 'EXWORKSNO',
    }
];


class TablePages extends Component<Props, State>  {
    constructor(props: any) {
        super(props);
        this.state = {
            data: [],
            pageNo: 1,
            pageSize: 10,
            total: 0
        }
    }
    componentDidMount() {
        this.getFixedAsset();
    }
    getFixedAsset = () => {
        const _self = this;
        const { dispatch } = _self.props;
        const { pageNo, pageSize } = _self.state;
        dispatch({
            type: 'table/queryTableData',
            payload: {
                selparam: "",
                leftdition: "",
                condition: "order by t.FIXED_ASSET_NO",
                pageNo: pageNo,
                pageSize: pageSize,
                dataowner: 'BHTPMS'
            }
        })
    }
    onChange = (page: number) => {
        this.setState({
            pageNo: page
        });
        this.getFixedAsset();
    };
    render() {
        const {total, pageNo, pageSize } = this.state;
        const {table}=this.props;
        const {data}=table;
        return (
            <PageHeaderWrapper>
                <Card>
                    <Table columns={columns}
                        pagination={{
                            current: pageNo,
                            pageSize: pageSize,
                            total: total,
                            onChange: this.onChange
                        }}
                        dataSource={data} />
                </Card>
            </PageHeaderWrapper>
        )
    }
}




export default connect(({ table, loading }: { table: TableModelState; loading: Loading }) => ({
    table,
    loading: loading.models.index,
}))(TablePages);
